#!/bin/bash
set -euo pipefail

# Usage: run_local_turritopsis.sh EPOCHS R N F PID EXTRA_ARGS
# Example: ./scripts/run_local_turritopsis.sh 30 5 4 1 0 "--dyn46"

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
BIN="$ROOT_DIR/turritopsis_full"

EPOCHS=${1:-30}
R=${2:-5}
N=${3:-4}
F=${4:-1}
PID=${5:-0}
EXTRA_ARGS=${6:-}

pushd "$ROOT_DIR" >/dev/null
go build -o turritopsis_full ./cmd/turritopsis_full

START_TS=$(date -Iseconds)
./turritopsis_full --epochs "$EPOCHS" --r "$R" --n "$N" --f "$F" --pid "$PID" $EXTRA_ARGS | tee run.log
END_TS=$(date -Iseconds)

# Export metrics if generator exists in protocol
if [ -f "$ROOT_DIR/turritopsis_metrics.csv" ]; then
  echo "Local run completed: $START_TS -> $END_TS"
  echo "Metrics CSV: $ROOT_DIR/turritopsis_metrics.csv"
fi

if [ -f "$ROOT_DIR/turritopsis_metrics.json" ]; then
  echo "Metrics JSON: $ROOT_DIR/turritopsis_metrics.json"
fi

popd >/dev/null




